/**
 * Created by Administrator on 2017/8/28 0028.
 */
import * as api from '../api/resource.js'
import * as types from './mutation-types'

let timeOutNum = 300

export const userLogin = ({commit}, options) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      api.judgeUser(options).then((res) => {
        commit(types.USER_LOGIN, {res: res})
        resolve(res)
      }).catch((error) => {
        console.log(error)
        reject(error)
      })
    }, timeOutNum)
  })
}

// client的增删改查
export const addClient = ({commit}, options) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      api.addClient(options).then((res) => {
        commit(types.BIMSERVER_ADDCLIENT, {res: res})
        resolve(res)
      }).catch((error) => {
        console.log(error)
        reject(error)
      })
    })
  })
}

export const deleteClient = ({commit}, options) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      api.deleteClient(options).then((res) => {
        commit(types.BIMSERVER_DELETECLIENT, options)
        resolve(res)
      }).catch((error) => {
        console.log(error)
        reject(error)
      })
    })
  })
}

export const updateClient = ({commit}, options) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      api.updateClient(options).then((res) => {
        commit(types.BIMSERVER_UPDATE_CLIENT, options)
        resolve(res)
      }).catch(err => {
        console.log(err)
        reject(err)
      })
    })
  })
}
